﻿@using Microsoft.Extensions.Localization
@using Microsoft.Extensions.Options
@using Volo.Abp.AspNetCore.MultiTenancy
@using Volo.Abp.AspNetCore.Mvc.AntiForgery
@using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy.Localization
@using Volo.Abp.AspNetCore.Mvc.UI.Theme.Uplon.Bundling
@using Volo.Abp.AspNetCore.Mvc.UI.Theme.Uplon.Themes.Uplon.Components.MainNavbar
@using Volo.Abp.AspNetCore.Mvc.UI.Theme.Uplon.Themes.Uplon.Components.PageAlerts
@using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Components
@using Volo.Abp.MultiTenancy
@inject IAbpAntiForgeryManager AbpAntiForgeryManager
@inject IBrandingProvider BrandingProvider
@inject IOptions<MultiTenancyOptions> MultiTenancyOptions
@inject ICurrentTenant CurrentTenant
@inject IStringLocalizer<AbpUiMultiTenancyResource> MultiTenancyStringLocalizer
@inject ITenantResolveResultAccessor TenantResolveResultAccessor

@{
    Layout = null;
    AbpAntiForgeryManager.SetCookie();
    var containerClass = ViewBag.FluidLayout == true ? "container-fluid" : "container"; //TODO: Better and type-safe options
    var bodyClass = string.IsNullOrWhiteSpace(ViewBag.BodyThemes) ? "with-side-menu control-panel control-panel-compact" : ViewBag.BodyThemes;
    var projectName = ViewBag.Title == null ? BrandingProvider.AppName : ViewBag.Title;
}

<!DOCTYPE html>

<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">

    <title>@projectName</title>

    <abp-style-bundle name="@UplonThemeBundles.Styles.Global" />

    @await RenderSectionAsync("styles", false)
</head>
<body class="@bodyClass">

    @(await Component.InvokeAsync<MainNavbarViewComponent>())

    <div class="@containerClass">
        <abp-row>
            <abp-column size-md="_4" offset-md="_4">
                @if (MultiTenancyOptions.Value.IsEnabled &&
                    (TenantResolveResultAccessor.Result?.AppliedResolvers?.Contains(CookieTenantResolveContributor.ContributorName) == true))
                {
                    <div class="tenant-switch-box" style="background-color: #eee; margin-bottom: 20px; color: #000; padding: 10px; text-align: center;">
                        <span style="color: #666;">@MultiTenancyStringLocalizer["Tenant"]: </span>
                        <strong>
                            @if (CurrentTenant.Id == null)
                            {
                                <i>@MultiTenancyStringLocalizer["NotSelected"]</i>
                            }
                            else
                            {
                                @(CurrentTenant.Name ?? CurrentTenant.Id.Value.ToString())
                            }
                        </strong>
                        (<a id="AbpTenantSwitchLink" style="color: #333; cursor: pointer">@MultiTenancyStringLocalizer["Switch"]</a>)
                    </div>
                }
                @(await Component.InvokeAsync<PageAlertsViewComponent>())
                @RenderBody()
            </abp-column>
        </abp-row>
    </div>

    <abp-script-bundle name="@UplonThemeBundles.Scripts.Global" />

    <script type="text/javascript" src="~/Abp/ApplicationConfigurationScript"></script>
    <script type="text/javascript" src="~/Abp/ServiceProxyScript"></script>

    @await RenderSectionAsync("scripts", false)

</body>
</html>